package com.hdit.mgr
{
	import mx.logging.ILogger;
	import mx.logging.Log;
	import mx.logging.LogEventLevel;
	import mx.logging.LogLogger;
	import mx.logging.targets.TraceTarget;
	
	/**
	 * 日志管理类
	 * 
	 **/
	public class LogMgr
	{
		
		public static var initialized:Boolean=false;
		
		/**是否允许输出到flashlog.txt日志文件**/
		private static var enabled:Boolean;
		
		private static var logger:ILogger;
		private static var logTarget:TraceTarget

		public static function init(enabled:Boolean):void
		{
			if (logger == null && logTarget == null)
			{ 
				logger=new LogLogger("Global");
				logTarget=new TraceTarget();
				logTarget.fieldSeparator="  ";
				logTarget.level=LogEventLevel.ALL;
				logTarget.includeCategory=true;
				logTarget.includeDate=true;
				logTarget.includeLevel=true;
				logTarget.includeTime=true;
				logTarget.addLogger(logger);
				Log.addTarget(logTarget);
				initialized=true;
				LogMgr.enabled=enabled;
				if(LogMgr.enabled)
					info("初始化日志完毕!");
			} 
		}    
		
		public static function info(message:String, ... parameters):void
		{ 
			if(LogMgr.enabled && Log.isInfo())
				logger.info(message,parameters);
		}
		
		public static function debug(message:String, ... parameters):void
		{
			if(LogMgr.enabled && Log.isDebug())
				logger.debug(message,parameters);
		}
		
		public static function error(message:String, ... parameters):void
		{
			if(LogMgr.enabled && Log.isError())
				logger.error(message,parameters);
		}
		
		public static function warn(message:String, ... parameters):void
		{
			if(LogMgr.enabled && Log.isWarn())
				logger.warn(message,parameters);
		}
	}
}
